# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import csv
import datetime

class LagouPipeline:
    def process_item(self, item, spider):
        date = str(datetime.date.today())#获取当前时间
        filename = ("lagou_{}_job.csv".format(date))
        #item类似字典结构，item.get(key)可以获取所有的key，但是get(value)不行，会调出整个字典结构的数据
        with open(filename, "a", encoding="utf-8-sig") as file:
            csv_writer = csv.writer(file)
            csv_writer.writerow(tuple([item.get(key) for key in item.keys()]))

        return item
